<?php
/**
 * View Nuovo Contatto - LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    16-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript">
//<![CDATA[

    $(document).ready(function() {
                            
        $("#partner_name").rules("add", {
            required: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $(".checkbox").rules("add", {
            required: true,
            messages: {
                required: "<?php echo sprintf( ERR_EMPTY_SELECT, 'Tipo' )?>"
            }
        });

        $("#partner_email").rules("add", {
            email: true,
            messages: {
                email: "<?php echo ERR_EMAIL ?>"
            }
        });

        $("#partner_phone_prefix").rules("add", {
            digits: true,
            rangelength: [1, 4],
            messages: {
                digits : "<?php echo sprintf( ERR_FORMAT, 'Tel. Principale' )?>",
                rangelength : "<?php echo sprintf( ERR_FORMAT, 'Tel. Principale' )?>"
            }
        });

        $("#partner_phone_number").rules("add", {
            digits: true,
            rangelength: [1, 10],
            messages: {
                digits : "<?php echo sprintf( ERR_FORMAT, 'Tel. Principale' )?>",
                rangelength : "<?php echo sprintf( ERR_FORMAT, 'Tel. Principale' )?>"
            }
        });

        $("#partner_fax_prefix").rules("add", {
            digits: true,
            rangelength: [1, 4],
            messages: {
                digits : "<?php echo sprintf( ERR_FORMAT, 'Fax' )?>",
                rangelength : "<?php echo sprintf( ERR_FORMAT, 'Fax' )?>"
            }
        });

        $("#partner_fax_number").rules("add", {
            digits: true,
            rangelength: [1, 10],
            messages: {
                digits : "<?php echo sprintf( ERR_FORMAT, 'Fax' )?>",
                rangelength : "<?php echo sprintf( ERR_FORMAT, 'Fax' )?>"
            }
        });       
        
        $("#partner_cap").rules("add", {
            digits: true,
            rangelength: [5, 5],
            range: [0, 98100],
            messages: {
                digits : "<?php echo  sprintf( ERR_FORMAT, 'CAP' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'CAP' )?>",
                range : "<?php echo  sprintf( ERR_FORMAT, 'CAP' )?>"
            }
        });
        
        $("#partner_city").rules("add", {
            required: {
                depends: function(element) {
                    return ($('#partner_street').val() != '' || 
                            $('#partner_street_number').val() != '' );
                }
            },
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $("#partner_province_id").rules("add", {
            required: {
                depends: function(element) {
                    return ($('#partner_street').val() != '' || 
                            $('#partner_street_number').val() != '' ||
                            $('#partner_city').val() != '');
                }
            },
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });
        
        validator.groups = {partner_phone_prefix: "partner_phone", partner_phone_number: "partner_phone", 
                            partner_fax_prefix: "partner_fax", partner_fax_prefix: "partner_fax", 
                            partner_street: "address", partner_city: "address", partner_province_id: "address"
                            }        
    });
    
    //]]>
</script>

<div class="info">
    <h2>Gestisci Partner</h2>
    <div>Per inserire un nuovo post...</div>
    <div>I campi contrassegnati da <span class="req">*</span> sono obbligatori!</div>
</div>

<form class="fab" name="partnerForm" id="partnerForm" action="/admin/partners/info/id/<?php echo $this->partner_id ?>" method="post" enctype="multipart/form-data">
    <ul>
	<li class="paging-context ">
	    <table class="pgStyle1 circle2" cellspacing="0">
		<tr>
		    <td class="c selected">
			<var>1</var>
		    </td>
		    <td class="t">
			<b id="pagecircle1">Informazioni Partner</b>
		    </td>
		    <td class="c ">
			<var>2</var>
		    </td>
		    <td class="t">
			<b id="pagecircle2">Associa</b>
		    </td>
		</tr>
	    </table>
	</li>
    </ul>
    <div id="content">   
        <ul>        
            <li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none'?>">
                <h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
                <p id="errorMsg">
                    Di seguito trovi evidenziati gli errori riscontrati.
                    <?php var_dump( $this->errorMsg ) ?>
                </p>
            </li>
            <li class="<?php echo  $this->errorMsg['partner_name'] ? 'error' : '' ?>">
                <div class="float-left">
                    <label class="desc <?php echo  $this->errorMsg['partner_name'] ? 'error' : '' ?>">Denominazione<span class="req">*</span></label>
                    <span>
                        <input id="partner_name" name="partner_name" class="field text medium" size="20" type="text" maxlength="255" value="<?php echo  $this->data['partner_name'] ?>" />
                    </span>
                </div>
                <p class="error" style="<?php echo  $this->errorMsg['partner_name'] ? 'display:block' : '' ?>"><?php echo  $this->errorMsg['partner_name'] ?></p>
            </li>

            <li class="<?php echo  $this->errorMsg['partner_types'] ? 'error' : '' ?>">
                <div class="float-left">
                    <label class="desc <?php echo  $this->errorMsg['partner_types'] ? 'error' : '' ?>">Tipo<span class="req">*</span></label>
                    <span class="input">
                    <?php foreach( $this->partner_types AS $k => $type ): ?>
                        <input class="field checkbox" name="partner_types[]" id="<?php echo $k?>" type="checkbox" value="<?php echo $k?>" <?php echo ( $this->data['partner_types'] AND in_array( $k, $this->data['partner_types'] ) ) ? 'checked="checked"' : '' ?> />
                        <label for="<?php echo $k?>" class="choice"><?php echo $type?></label>
                    <?php endforeach; ?>
                    </span>
                </div>
                <p class="error" style="<?php echo  $this->errorMsg['partner_types'] ? 'display:block' : '' ?>"><?php echo  $this->errorMsg['partner_types'] ?></p>
            </li>

            <li class="section">
                <h3>Altre Info</h3>
            </li>

            <li class="<?php echo $this->errorMsg['partner_email'] ? 'error' : ''?>">
                <label class="desc <?php echo $this->errorMsg['partner_email'] ? 'error' : ''?>">Email</label>
                <div>
                    <span>
                        <input id="partner_email" name="partner_email" class="field text medium" type="text" maxlength="255" value="<?php echo $this->data['partner_email']?>" /> 
                    </span>
                </div>
                <p class="error" style="<?php echo $this->errorMsg['partner_email'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['partner_email']?></p>
            </li>

            <li class="<?php echo $this->errorMsg['partner_phone'] ? 'error' : ''?>">
                <label class="desc <?php echo $this->errorMsg['partner_phone'] ? 'error' : ''?>">Tel.</label>
                <div class="float-left">
                    <span class="input">
                        <input class="field text" id="partner_phone_prefix" name="partner_phone_prefix" type="text" size="4" maxlength="4" value="<?php echo $this->data['partner_phone_prefix']?>" /> / 
                        <label>Pref</label>
                    </span>

                    <span class="input">
                        <input class="field text" id="partner_phone_number" name="partner_phone_number" type="text" size="10" value="<?php echo $this->data['partner_phone_number']?>" /> 
                        <label>Numero</label>
                    </span>
                </div>
                <p class="error" style="<?php echo $this->errorMsg['partner_phone'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['partner_phone']?></p>
            </li>

            <li class="<?php echo $this->errorMsg['partner_fax'] ? 'error' : ''?>">
                <label class="desc <?php echo $this->errorMsg['partner_fax'] ? 'error' : ''?>">Fax</label>
                <div class="float-left">
                    <span class="input">
                        <input class="field text" id="partner_fax_prefix" name="partner_fax_prefix" type="text" size="4" maxlength="4" value="<?php echo $this->data['partner_fax_prefix']?>" /> / 
                        <label>Pref</label>
                    </span>

                    <span class="input">
                        <input class="field text" id="partner_fax_number" name="partner_fax_number" type="text" size="10" value="<?php echo $this->data['partner_fax_number']?>" /> 
                        <label>Numero</label>
                    </span>
                </div>
                <p class="error" style="<?php echo $this->errorMsg['partner_fax'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['partner_fax']?></p>
            </li>
            <li class="complex <?php echo $this->errorMsg['partner_address'] ? 'error' : ''?>">
                <label class="desc <?php echo $this->errorMsg['partner_address'] ? 'error' : ''?>">Indirizzo</label>
                <div>
                    <span class="input">
                        <input class="field text addr" name="partner_street" id="partner_street" size="50" type="text" value="<?php echo $this->data['partner_street']?>" />
                        <label>Via</label>
                    </span>
                    <span class="input">
                        <input class="field text addr" name="partner_street_number" id="partner_street_number" size="2" type="text" value="<?php echo $this->data['partner_street_number']?>" />
                        <label>N&deg;</label>
                    </span>
                    <span class="input">
                        <input class="field text addr" name="partner_loc" id="partner_loc" size="50" type="text" value="<?php echo $this->data['partner_loc']?>" />
                        <label>Localit&aacute;</label>
                    </span>
                    <span class="input">
                        <input class="field text addr" name="partner_city" id="partner_city" size="50" type="text" value="<?php echo $this->data['partner_city']?>" />
                        <label>Citt&aacute;</label>
                    </span>
                    <span class="input">
                        <input class="field text addr" name="partner_cap" id="partner_cap" size="10" type="text" value="<?php echo $this->data['partner_cap']?>" />
                        <label>CAP</label>
                    </span>

                    <span class="left">
                        <select class="field select addr" name="partner_province_id" id="partner_province_id">
                            <option value=""></option>
                            <?php foreach( $this->province AS $k => $provincia ): ?>
                            <option value="<?php echo $k?>" <?php echo ( $this->data['partner_province_id'] == $k ) ? 'selected="selected"' : ''?>><?php echo $provincia['province_long_name']?></option>
                            <?php endforeach; ?>
                        </select>
                        <label>Provincia</label>
                    </span>
                    <p class="error" style="<?php echo $this->errorMsg['partner_address'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['partner_address']?></p>
                </div>
            </li>

            <li class="section">
                <h3></h3>
            </li>	

            <li class="<?php echo $this->errorMsg['partner_notes'] ? 'error' : ''?>">
                <label class="desc <?php echo $this->errorMsg['partner_notes'] ? 'error' : ''?>">Note</label>
                <div>
                    <span>
                        <textarea id="partner_notes" class="field textarea small" name="partner_notes" rows="3" cols="100"><?php echo  htmlentities( $this->data['partner_notes'] ) ?></textarea>
                    </span>
                </div>
                <p class="error" style="<?php echo $this->errorMsg['partner_notes'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['partner_notes']?></p>
            </li>

        </ul>
    </div>
    <div id="formButtons">
        <button id="salva" type="submit" name="salva" value="salva" class="button positive">
            <img src="/images/admin/tick.png" alt="" />Continua
        </button>
        <button id="annulla" name="annulla" value="annulla" class="button negative">
            <img src="/images/admin/cross.png" alt="" />Annulla
        </button>
    </div>
</form>
